package com.ericcson.innerportalapp;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MainListArrayAdapter extends ArrayAdapter<MainListItem> {
	
	private int resource;

	public MainListArrayAdapter(Context context, int resource,
			List<MainListItem> objects) {
		super(context, resource, objects);
		this.resource = resource;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		MainListItem mainListItem = getItem(position);
		String name = mainListItem.getName();
		int id = mainListItem.getId();
		
		LayoutInflater layoutInflator = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		View listItemView = layoutInflator.inflate(resource, null);
		
		TextView textView = (TextView) listItemView.findViewById(R.id.list_item);
		ImageView imageView = (ImageView) listItemView.findViewById(R.id.imageView2);
		
		textView.setText(name);
		imageView.setImageResource(id);
		return listItemView;
	}
	
	

}
